package com.voicechat.firstmet.activity;

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.builder.TimePickerBuilder;
import com.bigkoo.pickerview.listener.CustomListener;
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
import com.bigkoo.pickerview.listener.OnTimeSelectListener;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.bigkoo.pickerview.view.TimePickerView;
import com.contrarywind.view.WheelView;
import com.google.gson.Gson;
import com.voicechat.firstmet.MainActivity;
import com.voicechat.firstmet.R;
import com.voicechat.firstmet.base.BaseActivity;
import com.voicechat.firstmet.bean.JsonBean;
import com.voicechat.firstmet.bean.MySelfInfoBean;
import com.voicechat.firstmet.client.OssClient;
import com.voicechat.firstmet.client.OssConfig;
import com.voicechat.firstmet.client.WsManager;
import com.voicechat.firstmet.imcontrol.ILoginView;
import com.voicechat.firstmet.imcontrol.LoginHelper;
import com.voicechat.firstmet.net.HTTPAPI;
import com.voicechat.firstmet.net.service.LoginService;
import com.voicechat.firstmet.utils.ConstantSet;
import com.voicechat.firstmet.utils.ConstellationUtils;
import com.voicechat.firstmet.utils.ParcelableUtils;
import com.voicechat.firstmet.utils.PhoneUtils;
import com.voicechat.firstmet.utils.PopUtils;
import com.voicechat.firstmet.utils.SDCardUtils;
import com.voicechat.firstmet.utils.SPUtils;
import com.voicechat.firstmet.utils.StatusBarUtils;
import com.voicechat.firstmet.utils.Utils;
import com.voicechat.firstmet.view.CircleImageView;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.File;
import java.io.FileNotFoundException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

import static com.voicechat.firstmet.utils.PopUtils.hidePopupWindow;

/**
 * @ProjectName: FirstMet
 * @Package: com.voicechat.firstmet.activity_imessage
 * @ClassName: RegisterActivity
 * @Description: 注册activity  设置资料页面
 * @Author: ljp
 * @CreateDate: 2018/8/28 17:53
 * @Version: 1.0
 */
public class RegisterActivity extends BaseActivity implements ILoginView {
    @BindView(R.id.iv_back)
    LinearLayout ivBack;
    @BindView(R.id.iv_choose)
    CircleImageView ivChoose;
    @BindView(R.id.tv_sex)
    TextView tvSex;
    @BindView(R.id.et_name)
    EditText etName;
    @BindView(R.id.tv_data)
    TextView tvData;
    @BindView(R.id.register_sure)
    TextView registerSure;
    private static final String IMAGE_FILE_LOCATION = ConstantSet.LOCALFILE;//temp file
    File file;
    Uri imageUri;
    @BindView(R.id.image_view)
    ImageView imageView;
    @BindView(R.id.tv_place)
    TextView tvPlace;
    private TimePickerView pvCustomLunar;
    private Bitmap photo;
    private String TAG = "RegisterActivity";
    private String mobile;
    private String sex;
    private String picture;
    private Date dateF;
    private String userId;
    //城市数据list
    private ArrayList<JsonBean.DataBean> options1Items;
    private ArrayList<ArrayList<String>> options2Items;
    private String province;
    private String city;

    @Override
    protected int setStatusBarColor() {
        return 0;
    }

    @Override
    protected boolean isSettingStatusBarText() {
        return false;
    }

    @Override
    protected int loadLayout() {
        return R.layout.activity_register;
    }

    @Override
    protected void initLayout(Bundle savedInstanceState) {
        ButterKnife.bind(this);
        //透明状态栏
        StatusBarUtils.Full(this);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            this.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        }
        mobile = getIntent().getStringExtra("mobile");
        initView();
        initLunarPicker();
    }

    private void initView() {
        MySelfInfoBean.ObjectBean mySeleInfo = MySelfInfoBean.ObjectBean.CREATOR.createFromParcel(ParcelableUtils.unmarshall(
                SPUtils.getEditoString(SPUtils.SP_MYSELFINFO)));
        userId = mySeleInfo.getId();
        photo = null;
        ivChoose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                setPopuWindow();
            }
        });
        tvData.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pvCustomLunar.show();
            }
        });
        registerSure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (ContextCompat.checkSelfPermission(activity, Manifest.permission.READ_PHONE_STATE)
                        != PackageManager.PERMISSION_GRANTED) {
                    ActivityCompat.requestPermissions(activity, new String[]{
                            Manifest.permission.READ_PHONE_STATE}, 1);
                } else {
                    setSureRegister();
                }
            }
        });
        tvSex.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showSexPopWindow();
            }
        });
        initJsonData();
    }

    /**
     * @return
     * @method
     * @description 注册按钮事件条件判断
     * @date: 2018/8/31 16:59
     * @author: ljp
     */
    private void setSureRegister() {
        String s = tvSex.getText().toString();
        String birth = tvData.getText().toString();
        String name = etName.getText().toString().trim();
        if (TextUtils.isEmpty(name)) {
            toast_MakeText("请输入昵称");
        } else if (TextUtils.isEmpty(picture)) {
            toast_MakeText("请上传头像");
        } else if (TextUtils.isEmpty(sex)) {
            toast_MakeText("请选择性别");
        } else if (TextUtils.isEmpty(birth)) {
            toast_MakeText("请选择出生日期");
        } else if (TextUtils.isEmpty(province)) {
            toast_MakeText("请选择所在地");
        } else {
            String substring = birth.substring(0, 4);
            String time = getTime(new Date());
            String substring2 = time.substring(0, 4);
            int year = (Integer.parseInt(substring2)) - (Integer.parseInt(substring));
            if (year == 0 || year < 18) {
                toast_MakeText("您还未成年");
            } else {
                //注册
                SimpleDateFormat format = new SimpleDateFormat("MM");
                SimpleDateFormat format2 = new SimpleDateFormat("dd");
                String moth;
                if (format.format(dateF).substring(0, 1).equals("0")) {
                    moth = format.format(dateF).substring(1, 2);
                } else {
                    moth = format.format(dateF);
                }
                String day = format2.format(dateF);
                //获取星座
                String constellation = ConstellationUtils.getConstellation(Integer.parseInt(moth), Integer.parseInt(day));
                String deviceInfo = PhoneUtils.getDeviceInfo(context);
                String s1 = Utils.spitString(picture);
                //Log.i(TAG, "setSureRegister: ----constellation----"+constellation);
                //请求
                LoginService.addData(userId, SPUtils.getEditoString(SPUtils.SP_TOKEN),
                        s1, sex, name, birth, constellation, deviceInfo, city, province).subscribe(mySelfInfoBean -> {
                    Log.i(TAG, "setSureRegister: ----------" + mySelfInfoBean.toString());
                    if (mySelfInfoBean.getCode() == HTTPAPI.RETURN_CODE_TYPE.RETRUN_SUCCESS) {
                        LoginHelper loginHelper = new LoginHelper(this);
                        MySelfInfoBean.ObjectBean object = mySelfInfoBean.getObject();
                        SPUtils.setEditorKeyValue(SPUtils.SP_PHONE, mobile);
                        SPUtils.setEditorKeyValue(SPUtils.SP_TOKEN, object.getToken());
                        SPUtils.setEditorKeyValue(SPUtils.SP_MYSELFINFO, ParcelableUtils.marshall(object));
                        toast_MakeText(mySelfInfoBean.getMsg());
                        WsManager.getInstance(context).init(mySelfInfoBean.getObject().getId());
                        if(mySelfInfoBean.getMap() != null && mySelfInfoBean.getMap().getUserSig() != null){
                            SPUtils.setEditorKeyValue(SPUtils.SP_USERSIG, mySelfInfoBean.getMap().getUserSig());
                            loginHelper.login(object.getId(),mySelfInfoBean.getMap().getUserSig());
                        }else {
                            loginHelper.login(object.getId(),SPUtils.getEditoString(SPUtils.SP_USERSIG));
                        }
                    } else {
                        toast_MakeText(mySelfInfoBean.getMsg());
                    }
                }, throwable -> {
                    Log.i(TAG, "setSureRegister: ----------" + throwable.toString());
                    toast_MakeText(getResources().getString(R.string.net_error));
                });
            }
            //Log.i(TAG, "setSureRegister: -----"+year);
        }
    }

    private String getTime(Date date) {//可根据需要自行截取数据显示
        // Log.d("getTime()", "choice date millis: " + date.getTime());
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        return format.format(date);
    }

    /**
     * @return
     * @method
     * @description 日期选择框
     * @date: 2018/8/31 16:58
     * @author: ljp
     */
    private void initLunarPicker() {
        Calendar selectedDate = Calendar.getInstance();//系统当前时间
        Calendar startDate = Calendar.getInstance();
        startDate.set(1900, 1, 23);
        Calendar endDate = Calendar.getInstance();
        Calendar cd = Calendar.getInstance();
        endDate.set(cd.get(Calendar.YEAR), cd.get(Calendar.MONTH), cd.get(Calendar.DATE));
        //时间选择器 ，自定义布局
        pvCustomLunar = new TimePickerBuilder(this, new OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {//选中事件回调
                tvData.setText(getTime(date));
                dateF = date;
                // Toast.makeText(RegisterActivity.this, getTime(date), Toast.LENGTH_SHORT).show();
            }
        })
                .setDate(selectedDate)
                .setRangDate(startDate, endDate)
                .setLayoutRes(R.layout.pickerview_custom_lunar, new CustomListener() {
                    @Override
                    public void customLayout(final View v) {
                        final TextView tvSubmit = (TextView) v.findViewById(R.id.tv_finish);
                        TextView ivCancel = (TextView) v.findViewById(R.id.iv_cancel);
                        WheelView viewById = (WheelView) v.findViewById(R.id.year);
                        viewById.setTextSize(32.0f);
                        tvSubmit.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                pvCustomLunar.returnData();
                                pvCustomLunar.dismiss();
                            }
                        });
                        ivCancel.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                pvCustomLunar.dismiss();
                            }
                        });
                    }
                })
                .setType(new boolean[]{true, true, true, false, false, false})
                .isCenterLabel(false) //是否只显示中间选中项的label文字，false则每项item全部都带有label。
                .setDividerColor(Color.parseColor("#FF3B5E"))
                .build();
    }

    /**
     * @return
     * @method
     * @description 性别选择
     * @date: 2018/9/26 14:20
     * @author: ljp
     */
    private void showSexPopWindow() {
        View view = View.inflate(this, R.layout.popo_sex, null);
        PopUtils.showPopupWindow(activity, view, false);
        TextView tvMan = (TextView) view.findViewById(R.id.sex_man);
        TextView tvWomen = (TextView) view.findViewById(R.id.sex_women);
        TextView tv_cancel = (TextView) view.findViewById(R.id.tv_cancel);
        tvMan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                tvSex.setText("男");
                sex = "1";
                PopUtils.hidePopupWindow();
            }
        });
        tvWomen.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                tvSex.setText("女");
                sex = "2";
                PopUtils.hidePopupWindow();
            }
        });
        tv_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PopUtils.hidePopupWindow();
            }
        });
    }

    /**
     * @return
     * @method
     * @description 头像
     * @date: 2018/8/31 11:30
     * @author: ljp
     */
    public void setPopuWindow() {
        View view = View.inflate(this, R.layout.pop_repl_picture, null);
        PopUtils.showPopupWindow(this, view, false);
        //实例化控件
        TextView tvPhotoAlbum = view.findViewById(R.id.tv_photo_album);
        TextView tvPhotograph = (TextView) view.findViewById(R.id.tv_photograph);
        TextView tv_cancel = (TextView) view.findViewById(R.id.tv_cancel);
        file = new File(IMAGE_FILE_LOCATION);
        if (!file.exists()) {
            SDCardUtils.makeRootDirectory(IMAGE_FILE_LOCATION);
        }
        file = new File(IMAGE_FILE_LOCATION + ConstantSet.USERTEMPPIC);
        imageUri = Uri.fromFile(file);//The Uri t
        //取消
        tv_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                hidePopupWindow();
            }
        });
        tvPhotograph.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //拍照
                if (Build.VERSION.SDK_INT >= 23) {
                    int checkCallPhonePermission = ContextCompat.checkSelfPermission(RegisterActivity.this, Manifest.permission.CAMERA);
                    if (checkCallPhonePermission != PackageManager.PERMISSION_GRANTED) {
                        ActivityCompat.requestPermissions(RegisterActivity.this, new String[]{Manifest.permission.CAMERA}, 222);
                        return;
                    } else {
                        openCamra();//调用具体方法
                    }
                } else {
                    openCamra();//调用具体方法
                }
            }
        });
        //相册
        tvPhotoAlbum.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //拍照
                if (Build.VERSION.SDK_INT >= 23) {
                    int checkCallPhonePermission = ContextCompat.checkSelfPermission(RegisterActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE);
                    if (checkCallPhonePermission != PackageManager.PERMISSION_GRANTED) {
                        ActivityCompat.requestPermissions(RegisterActivity.this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 223);
                        return;
                    } else {
                        openIcon();//调用具体方法
                    }
                } else {
                    openIcon();//调用具体方法
                }
            }
        });

    }

    /**
     * 裁剪的图片的uri
     */
    private Uri uritempFile = null;

    /**
     * @return
     * @method
     * @description 打开相机
     * @date: 2018/8/31 11:45
     * @author: ljp
     */
    private void openCamra() {
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);//action is capture
        intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
        startActivityForResult(intent, ConstantSet.TAKEPICTURE);//or TAKE_SMALL_PICTURE
        hidePopupWindow();
    }

    /**
     * @return
     * @method
     * @description 选择相册
     * @date: 2018/8/31 14:54
     * @author: ljp
     */
    private void openIcon() {
        Intent intent = new Intent(Intent.ACTION_PICK);
        intent.setType("image/*");
        startActivityForResult(intent, ConstantSet.SELECTPICTURE);
        hidePopupWindow();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode != RESULT_OK) {
            return;
        }
        switch (requestCode) {
            //设置头像
            case ConstantSet.TAKEPICTURE:
                Intent tcutIntent = new Intent(RegisterActivity.this, ClippingPageActivity.class);
                tcutIntent.putExtra("type", "takePicture");
                startActivityForResult(tcutIntent, ConstantSet.CROPPICTURE);
                break;
            case ConstantSet.SELECTPICTURE:
                if (data != null) {
                    String imagePath;
                    Uri uri = data.getData();
                    if (uri != null) {
                        if (!TextUtils.isEmpty(uri.getAuthority())) {
                            Cursor cursor = getContentResolver().query(uri,
                                    new String[]{MediaStore.Images.Media.DATA}, null, null, null);
                            if (null == cursor) {
                                Toast.makeText(this, "图片没找到", Toast.LENGTH_SHORT).show();
                                return;
                            }
                            cursor.moveToFirst();
                            imagePath = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA));
                            cursor.close();
                        } else {
                            imagePath = uri.getPath();
                        }
                        // Log.i(TAG, "onActivityResult: -------File-imagePath----"+ FileSizeUtil.getAutoFileOrFilesSize(imagePath));
                        Intent scutIntent = new Intent(RegisterActivity.this, ClippingPageActivity.class);
                        scutIntent.putExtra("type", "selectPicture");
                        scutIntent.putExtra("path", imagePath);
                        startActivityForResult(scutIntent, ConstantSet.CROPPICTURE);
                    } else {
                        Toast.makeText(this, "图片没找到", Toast.LENGTH_SHORT).show();
                        return;
                    }
                }
                break;
            case ConstantSet.CROPPICTURE:
                File fileImager = new File(ConstantSet.LOCALFILE + ConstantSet.USERINFO);
                if (fileImager != null && fileImager.length() != 0) {
                    uritempFile = Uri.fromFile(fileImager);
                }
                try {
                    if (uritempFile != null) {
                        photo = BitmapFactory.decodeStream(activity.getContentResolver().openInputStream(uritempFile));
                        ivChoose.setImageBitmap(photo); //把图片显示在ImageView控件上
                        imageView.setVisibility(View.GONE);
                        //上传图片到oss
                        setOssImage(uritempFile.getPath());
                    } else {
                        Toast.makeText(this, "图片没找到", Toast.LENGTH_SHORT).show();
                    }
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                }
                break;
        }
    }
    /**
     * @return
     * @method
     * @description 上传图片到oss服务器
     * @date: 2018/9/25 15:54
     * @author: ljp
     */
    private void setOssImage(String image) {
        String name = Utils.getMobile(mobile) + System.currentTimeMillis();
        new Thread(new Runnable() {
            @Override
            public void run() {
                OssClient.getInstance().init(context).
                        upload(name, image, OssConfig.HEAD, new OssClient.OnUploadFile() {
                            @Override
                            public void onUploadFileSuccess(String info) {
                                picture = info;
                            }
                            @Override
                            public void onUploadFileFailed(String errCode) {
                            }
                        });
            }
        }).start();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            if (PopUtils.isPopShowing()) {
                PopUtils.hidePopupWindow();
                return true;
            }
            exit();
         /*   Intent intent = new Intent(Intent.ACTION_MAIN);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.addCategory(Intent.CATEGORY_HOME);
            startActivity(intent);*/
            return true;
        }


        return super.onKeyDown(keyCode, event);
    }

    private long nowTime = 0;

    /**
     * 退出程序
     */
    private void exit() {
        if (PopUtils.isPopShowing()) {
            PopUtils.hidePopupWindow();
        } else if (System.currentTimeMillis() - nowTime < 2000) {
            // RongIM.getInstance().disconnect();
            removeAllActivity();
            System.exit(0);
        } else {
            toast_MakeText("再按一次退出程序...");
            nowTime = System.currentTimeMillis();
        }
    }


    /**
     * @return
     * @method
     * @description 城市选择器
     * @date: 2018/9/27 11:46
     * @author: ljp
     */
    private void showPickerView() {// 弹出选择器
        OptionsPickerView pvOptions = new OptionsPickerBuilder(this, new OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                //返回的分别是三个级别的选中位置
                String tx = options1Items.get(options1).getPickerViewText() +
                        options2Items.get(options1).get(options2) /*+
                        options3Items.get(options1).get(options2).get(options3)*/;
                // Toast.makeText(JsonDataActivity.this, tx, Toast.LENGTH_SHORT).show();
                province = options1Items.get(options1).getPickerViewText();
                city = options2Items.get(options1).get(options2);
                tvPlace.setText(tx);
            }
        })
                .setTitleText("城市选择")
                .setDividerColor(Color.parseColor("#FF3B5E"))
                .setTextColorCenter(Color.BLACK) //设置选中项文字颜色
                .setContentTextSize(20)
                .build();

        /*pvOptions.setPicker(options1Items);//一级选择器*/
        pvOptions.setPicker(options1Items, options2Items);//二级选择器
        // pvOptions.setPicker(options1Items, options2Items, options3Items);//三级选择器
        pvOptions.show();
    }

    /**
     * @return
     * @method
     * @description 城市数据解析
     * @date: 2018/9/27 11:22
     * @author: ljp
     */
    private void initJsonData() {//解析数据
        options1Items = new ArrayList<>();
        options2Items = new ArrayList<>();
        /**
         * 注意：assets 目录下的Json文件仅供参考，实际使用可自行替换文件
         * 关键逻辑在于循环体
         * */
        String JsonData = Utils.getJson(this, "city.json");//获取assets目录下的json文件数据
        ArrayList<JsonBean.DataBean> jsonBean = parseData(JsonData);//用Gson 转成实体
        /**
         * 添加省份数据
         *
         * 注意：如果是添加的JavaBean实体，则实体类需要实现 IPickerViewData 接口，
         * PickerView会通过getPickerViewText方法获取字符串显示出来。
         */
        options1Items = jsonBean;
        for (int i = 0; i < jsonBean.size(); i++) {//遍历省份
            ArrayList<String> cityList = new ArrayList<>();//该省的城市列表（第二级）
            ArrayList<String> provinceList = new ArrayList<>();//该省的城市列表（第二级）
            String provinceName = jsonBean.get(i).getName();
            provinceList.add(provinceName);//添加城市
            for (int c = 0; c < jsonBean.get(i).getCities().size(); c++) {//遍历该省份的所有城市
                String cityName = jsonBean.get(i).getCities().get(c);
                cityList.add(cityName);//添加城市
            }
            /**
             * 添加城市数据
             */
            options2Items.add(cityList);
        }
    }

    /**
     * @return
     * @method
     * @description //Gson 解析
     * @date: 2018/9/27 11:23
     * @author: ljp
     */
    public ArrayList<JsonBean.DataBean> parseData(String result) {
        ArrayList<JsonBean.DataBean> detail = new ArrayList<>();
        try {
            JSONObject jsonObject = new JSONObject(result);
            JSONArray data = jsonObject.getJSONArray("data");
            Gson gson = new Gson();
            for (int i = 0; i < data.length(); i++) {
                JsonBean.DataBean entity = gson.fromJson(data.optJSONObject(i).toString(), JsonBean.DataBean.class);
                detail.add(entity);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return detail;
    }

    @Override
    public void updateLoginState(boolean state) {

    }

    @Override
    public void onLoginSDKSuccess() {
        removeAllActivity();
        startActivity(new Intent(this, MainActivity.class));
        finish();

    }

    @Override
    public void onLoginSDKFailed(int errCode, String errMsg) {
        toast_MakeText("登录失败，请重试！");

    }

    @Override
    public void onLogoutSDKSuccess() {
        Log.i(TAG, "onLogoutSDKSuccess: ------登录城市------");
       /* removeAllActivity();
        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);*/
    }

    @Override
    public void onLogoutSDKFailed(int errCode, String errMsg) {

    }

    @OnClick({R.id.iv_back, R.id.tv_place})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.tv_place:
                showPickerView();
                break;
        }
    }
    /**
     * ⑨重写onRequestPermissionsResult方法
     * 获取动态权限请求的结果,再开启录制音频
     */
    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        if (requestCode == 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            setSureRegister();
        } else {
            Toast.makeText(this, "用户拒绝了权限", Toast.LENGTH_SHORT).show();
        }
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }
}